use crate::{BlockHeight, BlockId, TimeStamp, constants};

#[derive(Debug)]
pub struct MiscItemCache {
    latest_block_id_in_best_chain: BlockId,
    best_height: BlockHeight,
    time_best_received: TimeStamp,
    // potential_blocks_of_main_chain: HashSet<BlockId>, // TODO
}

impl Default for MiscItemCache {
    fn default() -> Self {
        Self::new()
    }
}

impl MiscItemCache {
    pub fn new() -> Self {
        Self {
            latest_block_id_in_best_chain: BlockId::new(constants::NULL_BLOCK_ID),
            best_height: 0,
            time_best_received: 0,
            // potential_blocks_of_main_chain: HashSet::new(),
        }
    }
}

impl MiscItemCache {
    pub fn read_latest_block_id_in_best_chain(&self) -> &BlockId {
        &self.latest_block_id_in_best_chain
    }
    pub fn read_best_height(&self) -> BlockHeight {
        self.best_height
    }
    pub fn read_time_best_received(&self) -> TimeStamp {
        self.time_best_received
    }
}

impl MiscItemCache {
    pub fn write_latest_block_id_in_best_chain(&mut self, block_id: &BlockId) {
        self.latest_block_id_in_best_chain = *block_id;
    }
    pub fn write_best_height(&mut self, height: BlockHeight) {
        self.best_height = height;
    }
    pub fn write_time_best_received(&mut self, time: TimeStamp) {
        self.time_best_received = time;
    }
}
